package com.mentaleye.dal.dao.mybatis;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mentaleye.dal.dao.CurriculumTempDao;
import com.mentaleye.dal.model.CurriculumTemp;
import com.mentaleye.dal.model.CurriculumTempExample;
import com.mentaleye.dal.model.CurriculumTempRlate;
import com.mentaleye.dal.model.CurriculumTempRlateExample;
import com.mentaleye.dal.service.CurriculumTempMapper;
import com.mentaleye.dal.service.CurriculumTempRlateMapper;

@Component
public class CurriculumTempDaoImpl implements CurriculumTempDao {

	@Autowired private CurriculumTempMapper curriculumTempMapper;

	@Autowired private CurriculumTempRlateMapper curriculumTempRlateMapper;
	public boolean addCurriculumTemp(CurriculumTemp curriculumTemp) {
		int rows = curriculumTempMapper.insertSelective(curriculumTemp);
		return rows>0;
	}

	public boolean editCurriculumTemp(CurriculumTemp curriculumTemp) {
		int rows = curriculumTempMapper.updateByPrimaryKeySelective(curriculumTemp);
		return rows>0;
	}

	public List<CurriculumTemp> queryCurriculumTemp(Map<String, Object> map) {
		return curriculumTempMapper.selectByMap(map);
	}

	public List<CurriculumTemp> queryCurriculumTemp(CurriculumTempExample example) {
		return curriculumTempMapper.selectByExample(example);
	}

	public boolean deleteCurriculumTemp(List<Integer> ids) {
		CurriculumTempExample example = new CurriculumTempExample();
		example.createCriteria().andCurriculumTempNoIn(ids);
		int rows = curriculumTempMapper.deleteByExample(example);
		return rows==ids.size();
	}

	public boolean saveRlate(Integer cno, Integer tmpNo, Integer sort) {
		CurriculumTempRlate rlate = new CurriculumTempRlate();
		rlate.setCurriculumNo(cno);
		rlate.setCurriculumTempNo(tmpNo);
		rlate.setSort(sort);
		int rows = curriculumTempRlateMapper.insert(rlate);
		return rows>0;
	}

	public boolean deleteRlate(List<Integer> ids, Integer tmpNo) {
		CurriculumTempRlateExample example = new CurriculumTempRlateExample();
		example.createCriteria().andCurriculumNoIn(ids).andCurriculumTempNoEqualTo(tmpNo);
		int rows = curriculumTempRlateMapper.deleteByExample(example);
		return rows>0;
	}

	public boolean updateRlate(Integer cno, Integer tmpNo, Integer sort) {
		CurriculumTempRlate rlate = new CurriculumTempRlate();
		rlate.setCurriculumNo(cno);
		rlate.setCurriculumTempNo(tmpNo);
		rlate.setSort(sort);
		int rows = curriculumTempRlateMapper.updateByPrimaryKey(rlate);
		return rows>0;
	}

	public CurriculumTemp getCurriculumTempByNo(Integer curriculumTempNo) {
		return curriculumTempMapper.selectByPrimaryKey(curriculumTempNo);
	}
	
	public List<CurriculumTemp> selectByExample(CurriculumTempExample example){
		return curriculumTempMapper.selectByExample(example);
	}
	
}
